package org.shopen.puremvc.controller.startup
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.utilities.statemachine.FSMInjector;
	import org.shopen.puremvc.ApplicationConstants;

	public class InjectFSMCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{
			var fsm:XML = 
			<fsm initial={ApplicationConstants.STATE_WELCOMING}>
			   <state name={ApplicationConstants.STATE_WELCOMING}>
			       <transition action={ApplicationConstants.ACTION_READ_STAGE} target={ApplicationConstants.STATE_READING}/>
			       <transition action={ApplicationConstants.ACTION_START_TESTING} target={ApplicationConstants.STATE_TESTING}/>
			   </state>
			    <state name={ApplicationConstants.STATE_READING} changed={ApplicationConstants.LOAD_THEORY_META}>
			       <transition action={ApplicationConstants.ACTION_READ_STAGE} target={ApplicationConstants.STATE_READING}/>
			       <transition action={ApplicationConstants.ACTION_START_TESTING} target={ApplicationConstants.STATE_TESTING}/>
			   </state>
			    <state name={ApplicationConstants.STATE_TESTING} changed={ApplicationConstants.START_TESTING}>
			       <transition action={ApplicationConstants.ACTION_END_TESTING} target={ApplicationConstants.STATE_SCORING}/>
			  </state>
			    <state name={ApplicationConstants.STATE_SCORING} changed={ApplicationConstants.START_SCORING}>
			       <transition action={ApplicationConstants.ACTION_READ_STAGE} target={ApplicationConstants.STATE_READING}/>
			       <transition action={ApplicationConstants.ACTION_START_TESTING} target={ApplicationConstants.STATE_TESTING}/>
			   </state>
			</fsm>;
			
			// Create and inject the StateMachine 
			var injector : FSMInjector = new FSMInjector(fsm);
			injector.inject();
		}
	}
}